	<style>
	.publish-div>div
	{
		width:21%;
		display:inline-block;
		
		margin:1% 2%;
		
		float:left;
		
		
	}
	
	.cat-div>div
	{
		width:30.6%;
		display:inline-block;
		
		padding:1%;
		
		
	}
	
	.cat-div span
	{
		padding-left:20px;
	}
	
	.cat-div>div>input
	{
		
		position:absolute;
		left:15px;
	}
	
	
	.publish-div img{ float:left }
	
	.publish-div
	{
		text-aligh:center;
		padding:2%;
	}
	
	.cut
	{
		position:absolute;
		top:-10px;
		right:-10px;
		
		width:20px;
		
	}
	
	</style>

	<div style="height:5px;"></div>
	
	<div   class="uinn ">
		<span class="sc-text sc-border-left ulev0">发布我的随手拍</span>
	</div>

	
		

	
		<!-- <div class="uinn c-wh    umar-t umar-b ">
			
			<input  type="text"  value="" placeholder="请输入主题" class="uinn" >  
		</div>
		
		<div style="height:5px;"></div> -->
			<form>
		
			<div class=" uinn c-wh  ub uf  umar-t "  style="box-sizing:border-box">
			
				<textarea class="uinn ub" rows="10" cols="" placeholder="你想要说的话" name="desc" id="desc" ></textarea>
			</div>
			
			<div class="publish-div c-wh">
				
			</div>
			
			
	
			<div class="publish-div c-wh">
			
				
				<div id="add_img" style="background-image:url(images/tianjia3.png);background-repeat:no-repeat;background-size:50%;background-position:50%;background-color:#EEEEEE">
					<img src="images/0.png"  width="100%" />
				</div>
				
				<br style="clear:both" />
				
			</div>
			
			<div   class="uinn ">
		<span class="sc-text  ulev0 uinn umar-t umar-b">所属圈子</span>
			</div>
	
			
			
					<div class="cat-div c-wh uinn ulev-1">
				
				<div>
				<input type="radio" name="cid" >
				<span class="ub ub-pc">
				慕斯圈
				</span>
				</div>
				<div>
				<input type="radio" name="cid" >
				<span class="ub ub-pc">
				蛋糕圈
				</span>
				</div>
				
				<div>
				<input type="radio" name="cid" >
				<span class="ub ub-pc">
				蛋糕圈
				</span>
				</div>
				<div>
				<input type="radio" name="cid" >
				<span class="ub ub-pc">
				蛋糕圈
				</span>
				</div>
				
				
			</div>
				
	<div style="height:100px">
		
	</div>
			</form>
			
</div>

		<div id="publish-icon" >
	        <div>
	           <div class="icon-left"   ng-click="go('back', 'fade')" ></div>
			  
	           <div id="icon-zhengque" class="yf-post" data-type="yes" ></div>
			   
	          
	        </div>
    	</div>
    <script src="js/yf.js"></script>	
	<script>
		window.onload=function(){//防止直接路径
			if(!window.angular){
				window.location.href="/index.html";
				
			}
		}
	</script>
	
	<script>
	
	var add_img = $("#add_img");
	
	var num = 0;
	
	var limit_num = 9;
	
	var images = {
		    localId: [],
		    serverId: []
		  };
	
	add_img.click(function(){
		/* 
		var img = "images/set_img1.png";
		add_img(img);
		return;
		 */
		if(num>=limit_num)
		{
			showMsg("至多可上传9张图片");
			return;
		}
		 
		wx.chooseImage({
			success: function (res) {
				
		        images.localId = res.localIds;
		        
		        if (images.localId.length == 0) {
		  	      	showMsg('请先选择图片');
					return;
		  	    }
		        
		        var i = 0; 
		        var length = images.localId.length;
		        images.serverId = [];
		        
		        function upload() 
		        {
					
					if(num>=limit_num-1)
					{
						add_img.fadeOut("fast");
							
					}
					
					var img;
					
		        	wx.uploadImage({
		        		localId: images.localId[i],
		      		    success: function (res) {
		      		    	i++;
		      		    	num++;
		      		    	images.serverId.push(res.serverId);
		      		    	img = res.serverId;
		      		    	//alert(images.localId[i-1]);
		      		    	add_img_div(images.localId[i-1],img);
		      		    	
		      		    	
		      		    	if(num>=limit_num)
							{
								return;
									
							}
		      		    	
		      		    	
		      		    	if(i<length)
		      		    	{
		      		    		upload();
		      		    	}
		      		    	
		      		    	
		      		    }
		        	});
		        }
		        
		        upload();
		    }
		});
	});
	
	
	function add_img_div(limg,simg)
	{
		
		
		
		var img_div = "<div class='debug_img' style='background-image:url("+limg+");background-repeat:no-repeat;background-size:100%;background-position:50%'>"
			+"<img src='images/0.png'  width='100%' />"
			+"<div class='cut' onclick='cut_img(this)'>"
			+"<img class='debug_cut'  src='images/cut2.png'  width='100%' />"
			+"<input type='hidden' name='media[]' value='"+simg+"' />"
			+"</div>"
			+"</div>";
			
			
			
	    	$(img_div).insertBefore("#add_img");
	    	
	}
	
	function cut_img(obj)
	{
		num--;
		$(obj).parent().fadeOut("fast");
		
		if(num==limit_num-1)
		{
			add_img.fadeIn("slow");
			
		}
	}
	
	
	
	$('.yf-post').click(function(){
		
		var _this = $(this);
		var type = _this.attr('data-type');
		if(type == 'done')
		{
			showMsg("已经发布完成了~");
		}
		else if(type == 'yes')
		{
			var data = {};
			var data_arr = $('form').serialize().replace(/\+/g,' ').split('&');
			for(var i=0;i<data_arr.length;i++)
			{
				var temp=data_arr[i].split('=');
				if(typeof(data[hungry.util.utf8_decode(temp[0])])!='undefined')
				{
					var arr=[];
					if(data[hungry.util.utf8_decode(temp[0])] instanceof Array)
					{
						arr=data[hungry.util.utf8_decode(temp[0])];
					}
					else
					{
						arr.push(data[hungry.util.utf8_decode(temp[0])]);
					}
						arr.push(hungry.util.utf8_decode(temp[1]));
						data[hungry.util.utf8_decode(temp[0])]=arr;
				}
				else
				{
					data[hungry.util.utf8_decode(temp[0])]=hungry.util.utf8_decode(temp[1]);
				}
			}
			_this.attr('data-type', 'no');
			
			var url = baseUrl+"Picture.php?act=uploadData";
			
			
			
			$.post(url,data,function(result){
				
				
				if(result.code == "CL02032")
				{
					//showMsg(result.content);
					_this.attr('data-type', 'done');
					showMsg("发布成功！");
					
				}
				else if(result.code == "CL02033")
				{
					
					showMsg("跟大家分享有趣的照片呗~");
					_this.attr('data-type', 'yes');
					
				}
				else if(result.code == "CL02034")
				{
					
					showMsg("说几句话呗~");
					$("＃desc").focus();
					_this.attr('data-type', 'yes');
					
				}
				else
				{
					showMsg("网络不给力阿！");
					_this.attr('data-type', 'yes');
				}
			},'json');
		}
		else
		{
			showMsg("数据提交中");
		}
	});
	
	function showMsg(msg)
	{
		alert(msg);
	}
	
	</script>	
